package training.bms.presentation;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;

import training.bms.business.Blog;
import training.bms.business.BlogController;

@ManagedBean
public class NewBlog {

	private Blog blog;
	private boolean blogSaved;

	public NewBlog(){
		this.blog = new Blog();
		this.blog.setName("Afif's Blog");
		this.blog.setDescription("My Blog");
	}

	public Blog getBlog() {
		return blog;
	}

	public void setBlog(Blog blog) {
		this.blog = blog;
	}
	public void saveBlog(){
		BlogController controller = new BlogController();
		FacesMessage message = new FacesMessage();

		controller.saveBlog(blog);
		setBlogSaved(true);
		message.setSummary("Blog has been successfully saved!");
		message.setSeverity(FacesMessage.SEVERITY_INFO);

		FacesContext context = FacesContext.getCurrentInstance();
		context.addMessage(null, message);
	}

	public boolean getBlogSaved() {
		return blogSaved;
	}

	public void setBlogSaved(boolean blogSaved) {
		this.blogSaved = blogSaved;
	}

}
